<template>
  <div>
    <header class="top">
      <div class="headTitle">
        <div>小米商城</div>
        <div>MIUI</div>
        <div>loT</div>
        <div>云服务</div>
        <div>金融</div>
        <div>有品</div>
        <div>小爱开放平台</div>
      </div>
      <div class="topRight">
        <div>登录</div>
        <div class="shopCart">
          <span><img src="../assets/imgs/icon-cart-checked.png" alt="" /></span>
          <span>购物车</span>
        </div>
      </div>
    </header>
    <nav class="nav">
      <div class="logoImg">
        <img
          src="../assets/imgs/mi-logo.png"
          style="width: 80px; height: 80px; background: #ff6600"
        />
      </div>
      <div class="navList">
        <div>电视</div>
        <div @mouseover="phone" @mouseout="phoneOut">小米手机</div>
        <div>RedMi红米</div>
        <div>笔记本</div>
        <div>路由器</div>
        <div>家电</div>
      </div>
      <div class="list">
        <div class="phoneList">
          <div
            v-for="(item, index) in phoneList"
            :key="index"
            class="content"
            v-if="isShow"
          >
            <div><img :src="item.mainImage" alt="" /></div>
            <div>{{ item.name }}</div>
            <div>{{ item.price }}</div>
          </div>
        </div>
      </div>
      <div class="search">
        <span></span>
        <div class="searchIcon">
          <img src="../assets/imgs/icon-search.png" />
        </div>
        <div class="clear"></div>
      </div>
    </nav>
  </div>
</template>

<script>
import axios from "axios";
import { data } from "../assets/json/nav.json";
export default {
  name: "NavHeader",
  data() {
    return {
      phoneList: [],
      isShow: false,
    };
  },
  methods: {
    phone() {
      axios
        .get("http://localhost:8080/static/json/nav.json")
        .then((response) => {
          console.log(response);
          this.phoneList = response.data.data.list;
          console.log(this.phoneList);
        });
      this.isShow = true;
    },
    phoneOut() {
      this.isShow = false;
    },
  },
};
</script>

<style lang="less" scoped>
.clear {
  clear: both;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #333333;
  height: 40px;
  line-height: 40px;
  font-size: 12px;
  padding-left: 30px;
  padding-right: 50px;
}
.headTitle {
  display: flex;
  color: #9c9ca0;
  div {
    margin-right: 10px;
  }
}
.topRight {
  display: flex;
  align-items: center;
  color: #9c9ca0;
  div {
    padding: 0 10px;
  }
}
.shopCart {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ff6600;
  span {
    color: #fff;
    padding: 0 3px;
  }
  img {
    width: 20px;
    height: 15px;
  }
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 30px;
  padding-right: 50px;
  margin-top: 40px;
  .search {
    width: 400px;
    height: 60px;
    line-height: 60px;
    border: 2px solid #e2e2e2;
    span {
      width: 2px;
      height: 60px;
      color: #e2e2e2;
    }
    .searchIcon {
      img {
        width: 20px;
        height: 20px;
        float: right;
        position: relative;
        top: 20px;
        right: 20px;
        border-left: 2px solid #e2e2e2;
        padding: 0 0 0 20px;
      }
    }
  }
}
.navList {
  display: flex;
  align-items: center;
  div {
    font-weight: bold;
    color: #393d43;
    margin: 0 10px;
  }
  div:hover{
    color: #ff6600;
  }
}
.list {
  position: absolute;
  top: 200px;
  left: 0;
  width: 100%;
  background-color: #fff;
  z-index: 10;
  .phoneList {
    display: flex;
    align-items: center;
    justify-content: space-around;
    img {
      width: 150px;
      height: 100px;
    }
    .content div {
      text-align: center;
    }
  }
}
</style>
